#include "imGeometry.h"
#include "imGraphics.h"

using imGraphics::iShader;
using imGraphics::iTexture;
using imGraphics::g_GFX;

Material::Material() {
	m_Diffuse = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
	m_Specular = Vector4(1.0f, 1.0f, 1.0f, 1.0f);

	m_Shader.operator=(g_GFX->GetNewShader());
	m_Shader->LoadShader("shaders/basic.fx");

	for(int i = 0; i < NUMTEXTURES; i++) {
		m_Tex[i] = imGraphics::g_DefTextures[i];
	}
}

void Material::SetTexture(std::string &TexturePath, int Index) {
	m_Tex[Index] = imGraphics::GetTexture(TexturePath);
}

void Material::SetTexture(iTexture* Tex, int Index) {
	m_Tex[Index] = Tex;
}

void Material::SetShader(iShader *Shader) {
	m_Shader = Shader;
}

iShader* Material::GetShader() {
	return m_Shader;
}

void Material::StartRender() {

	for(int i = 0; i < NUMTEXTURES; i++) {
		if(m_Tex[i] != NULL)
			m_Tex[i]->UseTexture(i);
	}

	m_Shader->SetDiffuse(m_Diffuse);
	m_Shader->SetSpecular(m_Specular);
	m_Shader->SetWireframe(false);
	m_Shader->FillMatrices();
	m_Shader->StartRender();
}

void Material::EndRender() {
	m_Shader->EndRender();
}